<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    const class2Type = {}
    const toString = class2Type.toString
    ;[
      'Boolean',
      'Number',
      'String',
      'Function',
      'Array',
      'Date',
      'RegExp',
      'Object',
      'Error',
      'Symbol'
    ].forEach((name) => {
      class2Type[`[object ${name}]`] = name.toLowerCase()
    })

    function toType(obj) {
      if (obj == null) {
        return obj + ''
      }
      return typeof obj === 'object' || typeof obj === 'function'
        ? class2Type[toString.call(obj)] || 'object'
        : typeof obj
    }
  </script>
</html>
